﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Castle.MicroKernel;
using System.Web.Routing;
using System.Web;

namespace QuartzMaster.Base
{
    public class ControllerFactory : DefaultControllerFactory
    {
          private readonly IKernel kernel;
 
            public ControllerFactory(IKernel kernel)
            {
                this.kernel = kernel;
            }
 
            public override void ReleaseController(IController controller)
            {
                kernel.ReleaseComponent(controller);
            }
 
            protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
            {
                if (controllerType == null)
                {
                    throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
                }
                return (IController)kernel.Resolve(controllerType);
            }
    }
}
